package org.gdgbologna.devfest.adapter;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

import org.gdgbologna.devfest.R;
import org.gdgbologna.resources.Session;
import org.gdgbologna.resources.Talk;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class SponsorAdapter extends BaseAdapter {


	class ViewHolder {
		ImageView	image;
		
		ViewHolder(View row){
			image = (ImageView) row.findViewById(R.id.image_sponsor);
			
		}
	}
	
	private LayoutInflater mInflater;
	private String[] images;
	private Application act;
	

	public SponsorAdapter(Context context, String[] _img) {
		// Cache the LayoutInflate to avoid asking for a new one each time.
		mInflater = LayoutInflater.from(context);
		act =  (Application) context;
		images = _img;
	}
	
	@Override
	public boolean isEnabled(int position){
		return false;
	}
	
	@Override
	public boolean areAllItemsEnabled(){
		return false;
	}
	
	/**
	 * The number of items in the list
	 */
	public int getCount() {
		return images.length;
	}

	/**
	 * Get an item
	 */
	public String getItem(int position) {
		return images[position];
	}

	/**
	 * Get the id of this mainType (defined in types.xml)
	 */
	public long getItemId(int position) {
		return position;
	}

	/**
	 * Make a view to hold each row.
	 * 
	 * @see android.widget.ListAdapter#getView(int, android.view.View,
	 *      android.view.ViewGroup)
	 */
	@TargetApi(16)
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.row_sponsor, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
            
        } else {
        	holder = (ViewHolder)convertView.getTag();
        }

		String image = getItem(position);
		
		int imageResource = act.getResources().getIdentifier("drawable/"+image, null, act.getPackageName());		
		if (imageResource != 0){
			holder.image.setImageDrawable(act.getResources().getDrawable(imageResource));
		}
	
		return convertView;
	}

}
